﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.PointCloud.Layer.CUiPOCNewPointCloudLayerCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.PointCloud.Editing;
using EngineeringInternalExtension;
using EngineeringInternalExtension.ModelObjects;
using System.Collections.ObjectModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.PointCloud.Layer;

public sealed class CUiPOCNewPointCloudLayerCmd : TxButtonCommand
{
  private CUiPOCNewPointCloudLayerEnabler m_enabler;

  public CUiPOCNewPointCloudLayerCmd() => this.m_enabler = new CUiPOCNewPointCloudLayerEnabler();

  public virtual string Category => PointCloudStringTable.CMD_POINT_CLOUD_CATEGORY;

  public virtual string Name => PointCloudStringTable.CMD_POINT_CLOUD_LAYER_NAME;

  public virtual string Tooltip => PointCloudStringTable.CMD_POINT_CLOUD_LAYER_TOOLTIP;

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("CreatePointCloudLayer");

  public virtual string Bitmap => "PointCloud.Layer.NewPointCloudLayer.bmp";

  public virtual string Description => PointCloudStringTable.CMD_POINT_CLOUD_LAYER_DESCRIPTION;

  public virtual bool Licensed => CApPointCloudUtilities.IsLicensed();

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.m_enabler;

  public virtual void Execute(object cmdParams) => this.CreateNewPointCloudLayer();

  private void CreateNewPointCloudLayer()
  {
    ITxPointCloud pointCloudInEditing = TxPointCloudRootEx.GetPointCloudInEditing();
    if (pointCloudInEditing == null)
      return;
    if (this.MaxAllowedLayersExceeded(pointCloudInEditing))
    {
      int num1 = (int) TxMessageBox.Show(PointCloudStringTable.MAX_NUMBER_OF_LAYER_EXCEEDED, PointCloudStringTable.CMD_POINT_CLOUD_LAYER_NAME, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
    }
    else
    {
      TxPointCloudLayerCreationDataEx layerCreationDataEx = new TxPointCloudLayerCreationDataEx(new CApPointCloudLayerNameGenerator().GenerateNewLayerName(pointCloudInEditing));
      CApPOCEditManagerApp.StartPointCloudEdit();
      try
      {
        TxPointCloudEx.CreatePointCloudLayer((ITxPointCloud) (pointCloudInEditing as TxPointCloud), layerCreationDataEx);
      }
      catch (TxPointCloudNotSupportedException ex)
      {
        int num2 = (int) TxMessageBox.Show(PointCloudStringTable.POINT_CLOUD_NOT_SUPPORTED, PointCloudStringTable.CMD_POINT_CLOUD_NAME, MessageBoxButtons.OK, MessageBoxIcon.Hand);
      }
      CApPOCEditManagerApp.EndPointCloudEdit();
      TxApplication.RefreshDisplay();
    }
  }

  private bool MaxAllowedLayersExceeded(ITxPointCloud ipointCloud)
  {
    return ((Collection<ITxPointCloudLayer>) TxPointCloudEx.GetAllLayers(ipointCloud)).Count >= TxPointCloudRootEx.GetMaxAllowedLayersInPointCloud();
  }
}
